package com.test.controller;

import com.test.domain.Account;
import com.test.domain.Result;
import com.test.domain.Utils;
import com.test.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/account")
public class AccountController {

    private final AccountService accountService;

    @Autowired
    public AccountController(AccountService accountService) {
        this.accountService = accountService;
    }

    @GetMapping("/accountList")
    public Result getAccountList(@RequestParam("phoneNumber")String phoneNumber){
        return Utils.success(accountService.getAccountList(phoneNumber));
    }

    @PostMapping("/insertAccount")
    public Result insertAccount(@RequestBody Account account){
        accountService.insertAccount(account);
        return Utils.success("ok");
    }

    @GetMapping("/delete")
    public Result deleteAccount(@RequestParam("accountNumber") String accountNumber,
                                @RequestParam("phoneNumber") String phoneNumber){
        accountService.deleteAccount(accountNumber,phoneNumber);
        return Utils.success("ok");
    }

}
